package com.ruixinzheng.mvpdemo.view;

import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

import androidx.appcompat.app.AppCompatActivity;

import com.ruixinzheng.mvpdemo.R;
import com.ruixinzheng.mvpdemo.presenter.MainBasePresenter;
import com.ruixinzheng.mvpdemo.presenter.MainBasePresenterImpl;

public class MainActivity extends AppCompatActivity implements MainBaseView {
    private static final String TEXT = "This is MVP design";

    private MainBasePresenter mPresenter;
    private TextView mTv;
    private Button mBt;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        mPresenter = new MainBasePresenterImpl();
        mPresenter.attachView(this);

        mTv = findViewById(R.id.tv);
        mBt = findViewById(R.id.bt);

        mTv.setText(TEXT + " +" + mPresenter.getCount());
        mBt.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                mPresenter.increaseCount();
            }
        });
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        mPresenter.detachView();
    }

    @Override
    public void updateText(int count) {
        mTv.setText(TEXT + " +" + count);
    }
}
